package com.meitianhui.convenitenbuy.module.wallet.http;

import com.meitianhui.convenitenbuy.base.BaseArrayResponse;
import com.meitianhui.convenitenbuy.base.BaseListResponse;
import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.http.RetrofitHelper;
import com.meitianhui.convenitenbuy.module.order.model.bean.EmptyInfo;
import com.meitianhui.convenitenbuy.module.wallet.model.CardRecordBean;
import com.meitianhui.convenitenbuy.module.wallet.model.CodeFlowBean;
import com.meitianhui.convenitenbuy.module.wallet.model.CouponBean;
import com.meitianhui.convenitenbuy.module.wallet.model.CouponDetailBean;
import com.meitianhui.convenitenbuy.module.wallet.model.FamilyCard;
import com.meitianhui.convenitenbuy.module.wallet.model.PaymentCodeBean;
import com.meitianhui.convenitenbuy.module.wallet.model.PropertyBean;
import com.meitianhui.convenitenbuy.module.wallet.model.RechargeBackInfoBean;
import com.meitianhui.convenitenbuy.module.wallet.model.RedPacketBean;
import com.meitianhui.convenitenbuy.module.wallet.model.StoreInfoBean;
import com.meitianhui.convenitenbuy.module.wallet.model.TempCard;
import com.meitianhui.convenitenbuy.module.wallet.model.TradeRecordBean;
import com.meitianhui.convenitenbuy.module.wallet.model.UsableChangeBean;
import com.meitianhui.convenitenbuy.module.wallet.model.UserPropertyBean;
import com.meitianhui.convenitenbuy.util.RxUtils;

import retrofit2.http.Query;
import rx.Observable;

/**
 * Created by Administrator on 2017/11/1.
 */

public class WalletApiDataSource implements WalletApi {
    private static volatile WalletApiDataSource instance = null;
    private WalletApiDataSource(){}
    public static WalletApiDataSource getInstance() {
        if (instance == null) {
            synchronized (WalletApiDataSource.class) {
                if (instance == null) {
                    instance = new WalletApiDataSource();
                }
            }
        }
        return instance;
    }
    @Override
    public Observable<BaseResponse<UserPropertyBean>> getUserProperty(@Query("user_token") String userToken) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getUserProperty(userToken).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseListResponse<TradeRecordBean>> getTradeDetail(@Query("app_token") String appToken, @Query("service") String service, @Query("page") String jsonPage, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 0).getTradeDetail(appToken, service, jsonPage, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseListResponse<PropertyBean>> getGoldDetail(@Query("app_token") String appToken, @Query("service") String service, @Query("page") String jsonPage, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 0).getGoldDetail(appToken, service, jsonPage, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<PaymentCodeBean>> getSecurityCode(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getSecurityCode(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<UsableChangeBean>> getUsableChange(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getUsableChange(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<EmptyInfo>> comparePassword(@Query("user_token") String userToken, @Query("payment_password") String password) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).comparePassword(userToken, password).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<CodeFlowBean>> getPaymentCode(@Query("app_token") String appToken) {
        return RetrofitHelper.createApi(WalletApi.class, true, 0).getPaymentCode(appToken).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<RechargeBackInfoBean>> getRechargeOrder(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getRechargeOrder(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseListResponse<RedPacketBean>> getRedPackets(@Query("user_token") String userToken, @Query("service") String service, @Query("page") String jsonPage, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getRedPackets(userToken, service, jsonPage, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseListResponse<Object>> openRedPacket(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).openRedPacket(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<CouponBean>> getCoupons(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getCoupons(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseListResponse<EmptyInfo>> verifyCode(@Query("app_token") String appToken, @Query("flow_no") String flowNo, @Query("security_code") String securityCode) {
        return RetrofitHelper.createApi(WalletApi.class, true, 0).verifyCode(appToken, flowNo, securityCode).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<StoreInfoBean>> getStore(@Query("app_token") String appToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 0).getStore(appToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<EmptyInfo>> payForOrder(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).payForOrder(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<EmptyInfo>> receivePay(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).receivePay(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseArrayResponse<FamilyCard>> getFamilyCards(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getFamilyCards(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<TempCard>> getTempCardCode(@Query("app_token") String appToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 0).getTempCardCode(appToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse> addTempCard(@Query("app_token") String appToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 0).addTempCard(appToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<EmptyInfo>> addCard(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).addCard(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<EmptyInfo>> unBind(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).unBind(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseListResponse<CardRecordBean>> getCardRecord(@Query("user_token") String userToken, @Query("service") String service, @Query("page") String jsonPage, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getCardRecord(userToken, service, jsonPage, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<EmptyInfo>> modifyCardRemark(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).modifyCardRemark(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<CouponDetailBean>> getCouponDetail(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String jsonParams) {
        return RetrofitHelper.createApi(WalletApi.class, true, 1).getCouponDetail(userToken, service, jsonParams).compose(RxUtils.rxSchedulerHelper());
    }

}
